﻿using System.Windows.Controls;
using System.Windows.Shapes;
using EventLogAnalyzer.ViewModel;

namespace EventLogAnalyzer.View
{
    /// <summary>
    /// Interaction logic for EventDetailsControl.xaml
    /// </summary>
    public partial class LogDistributionControl : UserControl
    {
        public LogDistributionControl()
        {
            InitializeComponent();
            Loaded += new System.Windows.RoutedEventHandler(LogDistributionControl_Loaded);
        }

        void LogDistributionControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            byOccurrances.IsChecked = true;
        }

        private void byDate_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            var dataContext = (LogDistributionViewModel)((RadioButton)sender).DataContext;
            dataContext.ArrangeLogGroupsAsPerTimeStampCommand.Execute(null);
        }

        private void byOccurrances_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            var dataContext = (LogDistributionViewModel)((RadioButton)sender).DataContext;
            dataContext.ArrangeLogGroupsAsPerOccurancesCommand.Execute(null);
        }

        private void byLevel_Checked(object sender, System.Windows.RoutedEventArgs e)
        {

        }

        private void Rectangle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var dataContext = (EventLogsGroupViewModel)((Rectangle)sender).DataContext;
            dataContext.ShowLogGroupDetailsCommand.Execute(null);
            e.Handled = true;
        }

        private void UserControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            ((LogDistributionViewModel)DataContext).SelectCommand.Execute(null);
        }

        private void Rectangle_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var dataContext = (EventLogsGroupViewModel)((Rectangle)sender).DataContext;
            dataContext.DrillDownCommand.Execute(null);
            e.Handled = true;
        }

        private void bySearch_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            var dataContext = (LogDistributionViewModel)((RadioButton)sender).DataContext;
            dataContext.ArrangeLogGroupsAsPerSearchCriteriaCommand.Execute(null);
        }
    }
}
